#define _CRT_SECURE_NO_WARNINGS
int maxDepth(struct TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }
    int right = maxDepth(root->right);
    int left = maxDepth(root->left);
    return right > left ? right + 1 : left + 1;
}

bool isBalanced(struct TreeNode* root)
{
    if (root == NULL)
    {
        return true;
    }
    int rightDepth = maxDepth(root->right);
    int leftDepth = maxDepth(root->left);
    return abs(rightDepth - leftDepth) < 2 && isBalanced(root->left) && isBalanced(root->right);
}